package com.company.pangu.aliyun.live.strategy;

import com.company.pangu.aliyun.live.enums.ProtocolType;
import com.company.pangu.aliyun.live.enums.PullProtocolType;
import com.company.pangu.aliyun.live.enums.PushProtocolType;

/**
 * <p>uri build context</p >
 *
 * @author youyoukele
 * @version 1.0
 * @date 2021/10/28
 */
public class UriBuildContext {

    /**
     * URI：用户请求对象相对地址，即原始URL中的/AppName/StreamName，其中StreamName包含扩展名。
     * 生成FLV播放地址时，URI为/AppName/StreamName.flv。
     * <p>
     * 生成HLS播放地址时，URI为/AppName/StreamName.m3u8。
     * <p>
     * 生成FLV转码播放地址时，URI为/AppName/StreamName_ID.flv。
     * <p>
     * 生成HLS转码播放地址时，URI为/AppName/StreamName_ID.m3u8。
     *
     * @param appName
     * @param streamName
     * @param protocolType
     * @return
     */
    public static String builder(String appName, String streamName, ProtocolType protocolType) {
        if (protocolType instanceof PullProtocolType) {
            PullProtocolType type = (PullProtocolType) protocolType;
            if (PullProtocolType.FLV == type) {
                return "/"+appName + "/" + streamName + "." + type.getExtension();
            } else if (PullProtocolType.HLS == type) {
                return "/"+appName + "/" + streamName + "." + type.getExtension();
            } else if (PullProtocolType.RTMP == type) {
                return "/"+appName + "/" + streamName;
            }
        } else if (protocolType instanceof PushProtocolType) {
            return "/"+appName + "/" + streamName;
        }
        throw new RuntimeException("protocol type illegal");
    }

}
